package com.dc.controller;

import com.dc.annotation.Log;
import com.dc.annotation.UnCheckToken;
import com.dc.entity.ro.SysConfigRO;
import com.dc.service.SysConfigService;
import com.dc.common.ResponseResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/config")
@Api(tags = "系统参数设置")
public class SysConfigController {

    @Resource
    SysConfigService sysConfigService;


    @ApiOperation(value = "查询系统参数配置列表", notes = "查询系统参数配置列表")
    @RequestMapping(value = "/selectConfigList", method = RequestMethod.GET)
    public ResponseResultVO selectConfigList() {
        return sysConfigService.selectConfigList();
    }


    @Log(title = "系统参数设置", businessDesc = "修改系统参数")
    @ApiOperation(value = "修改系统参数", notes = "修改系统参数")
    @RequestMapping(value = "/updateConfig", method = RequestMethod.POST)
    public ResponseResultVO updateConfig(@RequestBody SysConfigRO sysConfigRO) {
        return sysConfigService.updateConfig(sysConfigRO);
    }

    @ApiOperation(value = "通过key查询value", notes = "修改系统参数")
    @RequestMapping(value = "/selectValueByKey", method = RequestMethod.GET)
    @UnCheckToken(name = "/dc-control-system",url = "/config/selectValueByKey")
    public ResponseResultVO selectValueByKey(@RequestParam String key) {
        return sysConfigService.selectValueByKey(key);
    }


    @RequestMapping(value = "/selectConfigValue", method = RequestMethod.GET)
    public String selectConfigValue(@RequestParam String key) {
        return sysConfigService.getConfigValue(key);
    }
}
